package br.com.single.publico;

import br.com.single.modelo.estoque.Mvmovimevenda;
import java.util.List;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.PersistenceContext;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import org.springframework.roo.addon.dbre.RooDbManaged;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord;
import org.springframework.roo.addon.tostring.RooToString;
import org.springframework.transaction.annotation.Transactional;

@Entity
@Table(schema = "publico",name = "cdrepres")
@RooJavaBean
@RooToString
@RooJpaActiveRecord(versionField = "", table = "cdrepres", schema = "publico")
@RooDbManaged(automaticallyDelete = true)
public class Cdrepres {

	

	@Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "codigorepres",columnDefinition="codigonumero")
    private Integer codigorepres;

	
	
	
	@OneToMany(mappedBy = "repres")
    private Set<Mvmovimevenda> mvmovimevendas;

	@ManyToOne
    @JoinColumns({ @JoinColumn(name = "estadorepres", referencedColumnName = "codigoestado",columnDefinition="bpchar"), @JoinColumn(name = "codigocidaderepres", referencedColumnName = "codigocidade",columnDefinition="codigocidade") })
    private Cdcidade cdcidade;

	@ManyToOne
    @JoinColumn(name = "transprepres", referencedColumnName = "codigofornec",columnDefinition="codigonumero")
    private Cdfornec transprepres;

	@ManyToOne
    @JoinColumns({ @JoinColumn(name = "tabelaar", referencedColumnName = "codigotabela",columnDefinition="bpchar"), @JoinColumn(name = "arearepres", referencedColumnName = "elementabela",columnDefinition="classisimple") })
    private Cditemtabelageneri cditemtabelageneri;

	@ManyToOne
    @JoinColumns({ @JoinColumn(name = "tabelar1", referencedColumnName = "codigotabela",columnDefinition="bpchar"), @JoinColumn(name = "tiporepres", referencedColumnName = "elementabela",columnDefinition="classisimple") })
    private Cditemtabelageneri cditemtabelageneri1;

	@ManyToOne
    @JoinColumns({ @JoinColumn(name = "tabelaae", referencedColumnName = "codigotabela",columnDefinition="bpchar"), @JoinColumn(name = "atividrepres", referencedColumnName = "elementabela",columnDefinition="classisimple") })
    private Cditemtabelageneri cditemtabelageneri2;

	@ManyToOne
    @JoinColumns({ @JoinColumn(name = "tabelapo", referencedColumnName = "codigotabela",columnDefinition="bpchar"), @JoinColumn(name = "porterepres", referencedColumnName = "elementabela",columnDefinition="classisimple") })
    private Cditemtabelageneri cditemtabelageneri3;

	@ManyToOne
    @JoinColumns({ @JoinColumn(name = "tabelapr", referencedColumnName = "codigotabela",columnDefinition="bpchar"), @JoinColumn(name = "tabelapreco", referencedColumnName = "elementabela",columnDefinition="classisimple") })
    private Cditemtabelageneri cditemtabelageneri4;

	@Column(name = "nomerepres",columnDefinition="nomegrande")
    @NotNull
    private String nomerepres;

	@Column(name = "abrevirepres",columnDefinition="nomereduzi")
    @NotNull
    private String abrevirepres;

	@Column(name = "cnpjrepres",columnDefinition="cnpj")
    private String cnpjrepres;

	@Column(name = "ierepres",columnDefinition="ie")
    private String ierepres;

	@Column(name = "endererepres",columnDefinition="lograd")
    private String endererepres;

	@Column(name = "ceprepres",columnDefinition="cep")
    private String ceprepres;

	@Column(name = "bairrorepres",columnDefinition="bairro")
    private String bairrorepres;

	@Column(name = "cidaderepres",columnDefinition="cidade")
    private String cidaderepres;

	@Column(name = "fonerepres",columnDefinition="fone")
    private String fonerepres;

	@Column(name = "celularepres",columnDefinition="fone")
    private String celularepres;

	@Column(name = "contatrepres",columnDefinition="contat")
    private String contatrepres;

	@Column(name = "comissa",columnDefinition="percen")
    private String comissa;

	public Set<Mvmovimevenda> getMvmovimevendas() {
        return mvmovimevendas;
    }

	public void setMvmovimevendas(Set<Mvmovimevenda> mvmovimevendas) {
        this.mvmovimevendas = mvmovimevendas;
    }

	public Cdcidade getCdcidade() {
        return cdcidade;
    }

	public void setCdcidade(Cdcidade cdcidade) {
        this.cdcidade = cdcidade;
    }

	public Cdfornec getTransprepres() {
        return transprepres;
    }

	public void setTransprepres(Cdfornec transprepres) {
        this.transprepres = transprepres;
    }

	public Cditemtabelageneri getCditemtabelageneri() {
        return cditemtabelageneri;
    }

	public void setCditemtabelageneri(Cditemtabelageneri cditemtabelageneri) {
        this.cditemtabelageneri = cditemtabelageneri;
    }

	public Cditemtabelageneri getCditemtabelageneri1() {
        return cditemtabelageneri1;
    }

	public void setCditemtabelageneri1(Cditemtabelageneri cditemtabelageneri1) {
        this.cditemtabelageneri1 = cditemtabelageneri1;
    }

	public Cditemtabelageneri getCditemtabelageneri2() {
        return cditemtabelageneri2;
    }

	public void setCditemtabelageneri2(Cditemtabelageneri cditemtabelageneri2) {
        this.cditemtabelageneri2 = cditemtabelageneri2;
    }

	public Cditemtabelageneri getCditemtabelageneri3() {
        return cditemtabelageneri3;
    }

	public void setCditemtabelageneri3(Cditemtabelageneri cditemtabelageneri3) {
        this.cditemtabelageneri3 = cditemtabelageneri3;
    }

	public Cditemtabelageneri getCditemtabelageneri4() {
        return cditemtabelageneri4;
    }

	public void setCditemtabelageneri4(Cditemtabelageneri cditemtabelageneri4) {
        this.cditemtabelageneri4 = cditemtabelageneri4;
    }

	public String getNomerepres() {
        return nomerepres;
    }

	public void setNomerepres(String nomerepres) {
        this.nomerepres = nomerepres;
    }

	public String getAbrevirepres() {
        return abrevirepres;
    }

	public void setAbrevirepres(String abrevirepres) {
        this.abrevirepres = abrevirepres;
    }

	public String getCnpjrepres() {
        return cnpjrepres;
    }

	public void setCnpjrepres(String cnpjrepres) {
        this.cnpjrepres = cnpjrepres;
    }

	public String getIerepres() {
        return ierepres;
    }

	public void setIerepres(String ierepres) {
        this.ierepres = ierepres;
    }

	public String getEndererepres() {
        return endererepres;
    }

	public void setEndererepres(String endererepres) {
        this.endererepres = endererepres;
    }

	public String getCeprepres() {
        return ceprepres;
    }

	public void setCeprepres(String ceprepres) {
        this.ceprepres = ceprepres;
    }

	public String getBairrorepres() {
        return bairrorepres;
    }

	public void setBairrorepres(String bairrorepres) {
        this.bairrorepres = bairrorepres;
    }

	public String getCidaderepres() {
        return cidaderepres;
    }

	public void setCidaderepres(String cidaderepres) {
        this.cidaderepres = cidaderepres;
    }

	public String getFonerepres() {
        return fonerepres;
    }

	public void setFonerepres(String fonerepres) {
        this.fonerepres = fonerepres;
    }

	public String getCelularepres() {
        return celularepres;
    }

	public void setCelularepres(String celularepres) {
        this.celularepres = celularepres;
    }

	public String getContatrepres() {
        return contatrepres;
    }

	public void setContatrepres(String contatrepres) {
        this.contatrepres = contatrepres;
    }

	public String getComissa() {
        return comissa;
    }

	public void setComissa(String comissa) {
        this.comissa = comissa;
    }

	public Integer getCodigorepres() {
        return this.codigorepres;
    }

	public void setCodigorepres(Integer id) {
        this.codigorepres = id;
    }

	@PersistenceContext
    transient EntityManager entityManager;

	public static final EntityManager entityManager() {
        EntityManager em = new Cdrepres().entityManager;
        if (em == null) throw new IllegalStateException("Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)");
        return em;
    }

	public static long countCdrepreses() {
        return entityManager().createQuery("SELECT COUNT(o) FROM Cdrepres o", Long.class).getSingleResult();
    }

	public static List<Cdrepres> findAllCdrepreses() {
        return entityManager().createQuery("SELECT o FROM Cdrepres o", Cdrepres.class).getResultList();
    }

	public static Cdrepres findCdrepres(Integer codigorepres) {
        if (codigorepres == null || codigorepres == 0) return null;
        return entityManager().find(Cdrepres.class, codigorepres);
    }

	public static List<Cdrepres> findCdrepresEntries(int firstResult, int maxResults) {
        return entityManager().createQuery("SELECT o FROM Cdrepres o", Cdrepres.class).setFirstResult(firstResult).setMaxResults(maxResults).getResultList();
    }

	@Transactional
    public void persist() {
        if (this.entityManager == null) this.entityManager = entityManager();
        this.entityManager.persist(this);
    }

	@Transactional
    public void remove() {
        if (this.entityManager == null) this.entityManager = entityManager();
        if (this.entityManager.contains(this)) {
            this.entityManager.remove(this);
        } else {
            Cdrepres attached = Cdrepres.findCdrepres(this.codigorepres);
            this.entityManager.remove(attached);
        }
    }

	@Transactional
    public void flush() {
        if (this.entityManager == null) this.entityManager = entityManager();
        this.entityManager.flush();
    }

	@Transactional
    public void clear() {
        if (this.entityManager == null) this.entityManager = entityManager();
        this.entityManager.clear();
    }

	@Transactional
    public Cdrepres merge() {
        if (this.entityManager == null) this.entityManager = entityManager();
        Cdrepres merged = this.entityManager.merge(this);
        this.entityManager.flush();
        return merged;
    }
}
